package com.heima.article.controller;

import com.heima.article.service.ApArticleService;
import com.heima.common.constants.ArticleConstants;
import com.heima.model.common.dtos.ArticleHomeDto;
import com.heima.model.common.dtos.ArticleInfoDto;
import com.heima.model.common.dtos.ResponseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 陈辉
 * @data 2024 9:51
 */
@Slf4j
@RestController
@RequestMapping("/api/v1/article")
public class ApArticleController {

    @Autowired
    private ApArticleService apArticleService;

    /**
     * 加载首页
     *
     * @return
     */
    @PostMapping("load")
    public ResponseResult load(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.loadHotArticle(homeDto, ArticleConstants.LOADTYPE_LOAD_INDEX);
    }

    /**
     * 加载更多
     *
     * @return
     */
    @PostMapping("loadmore")
    public ResponseResult loadmore(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.load(homeDto,ArticleConstants.LOADTYPE_LOAD_MORE);
    }

    /**
     * 加载更新
     *
     * @return
     */
    @PostMapping("loadnew")
    public ResponseResult loadnew(@RequestBody ArticleHomeDto homeDto){
        return apArticleService.load(homeDto,ArticleConstants.LOADTYPE_LOAD_NEW);
    }

    /**
     * 加载文章行为-数据回显
     * @param articleInfoDto
     * @return
     */
    @PostMapping("/load_article_behavior")
    public ResponseResult loadArticleBehavior(@RequestBody ArticleInfoDto articleInfoDto){
        log.info("加载文章行为数据回显的数据是：{}",articleInfoDto);
        return apArticleService.loadArticleBehavior(articleInfoDto);
    }
}
